package java_class_work.week08.internet.tcp;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author Tiam
 * @Date 2022/11/1 10:58
 * @Description:
 */
public class TcpServer02 {
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(8888);
            Socket socket = serverSocket.accept();
            InputStream inputStream = socket.getInputStream();
            byte[] bytes = new byte[1024];
            int len = inputStream.read(bytes);
            System.out.println(new String(bytes,0,len));

            OutputStream outputStream = socket.getOutputStream();
            outputStream.write("服务端已收到,over".getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
